package com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ruoyi.pingan.annotation.CommonLog;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.entity.SxoGoodsCategoryJoin;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.param.SxoGoodsCategoryJoinAddParam;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.param.SxoGoodsCategoryJoinEditParam;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.param.SxoGoodsCategoryJoinIdParam;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.param.SxoGoodsCategoryJoinPageParam;
import com.ruoyi.pingan.fymodule.goodsinfo.goodscategoryjoin.service.SxoGoodsCategoryJoinService;
import com.ruoyi.pingan.fymodule.thirdpa.util.CommonResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;



import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 商品分类关联控制器
 *
 * @author wangy
 * @date  2025/07/25 16:48
 */
@Tag(name = "商品分类关联控制器")
@RestController
@Validated
public class SxoGoodsCategoryJoinController {

    @Resource
    private SxoGoodsCategoryJoinService sxoGoodsCategoryJoinService;

    /**
     * 获取商品分类关联分页
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "获取商品分类关联分页")
    @SaCheckPermission("/biz/goodscategoryjoin/page")
    @GetMapping("/biz/goodscategoryjoin/page")
    public CommonResult<Page<SxoGoodsCategoryJoin>> page(SxoGoodsCategoryJoinPageParam sxoGoodsCategoryJoinPageParam) {
        return CommonResult.data(sxoGoodsCategoryJoinService.page(sxoGoodsCategoryJoinPageParam));
    }

    /**
     * 添加商品分类关联
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "添加商品分类关联")
    @CommonLog("添加商品分类关联")
    @SaCheckPermission("/biz/goodscategoryjoin/add")
    @PostMapping("/biz/goodscategoryjoin/add")
    public CommonResult<String> add(@RequestBody @Valid SxoGoodsCategoryJoinAddParam sxoGoodsCategoryJoinAddParam) {
        sxoGoodsCategoryJoinService.add(sxoGoodsCategoryJoinAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑商品分类关联
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "编辑商品分类关联")
    @CommonLog("编辑商品分类关联")
    @SaCheckPermission("/biz/goodscategoryjoin/edit")
    @PostMapping("/biz/goodscategoryjoin/edit")
    public CommonResult<String> edit(@RequestBody @Valid SxoGoodsCategoryJoinEditParam sxoGoodsCategoryJoinEditParam) {
        sxoGoodsCategoryJoinService.edit(sxoGoodsCategoryJoinEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除商品分类关联
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "删除商品分类关联")
    @CommonLog("删除商品分类关联")
    @SaCheckPermission("/biz/goodscategoryjoin/delete")
    @PostMapping("/biz/goodscategoryjoin/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SxoGoodsCategoryJoinIdParam> sxoGoodsCategoryJoinIdParamList) {
        sxoGoodsCategoryJoinService.delete(sxoGoodsCategoryJoinIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取商品分类关联详情
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "获取商品分类关联详情")
    @SaCheckPermission("/biz/goodscategoryjoin/detail")
    @GetMapping("/biz/goodscategoryjoin/detail")
    public CommonResult<SxoGoodsCategoryJoin> detail(@Valid SxoGoodsCategoryJoinIdParam sxoGoodsCategoryJoinIdParam) {
        return CommonResult.data(sxoGoodsCategoryJoinService.detail(sxoGoodsCategoryJoinIdParam));
    }

    /**
     * 下载商品分类关联导入模板
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "下载商品分类关联导入模板")
    @GetMapping(value = "/biz/goodscategoryjoin/downloadImportTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void downloadImportTemplate(HttpServletResponse response) throws IOException {
        sxoGoodsCategoryJoinService.downloadImportTemplate(response);
    }

    /**
     * 导入商品分类关联
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "导入商品分类关联")
    @CommonLog("导入商品分类关联")
    @SaCheckPermission("/biz/goodscategoryjoin/importData")
    @PostMapping("/biz/goodscategoryjoin/importData")
    public CommonResult<JSONObject> importData(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(sxoGoodsCategoryJoinService.importData(file));
    }

    /**
     * 导出商品分类关联
     *
     * @author wangy
     * @date  2025/07/25 16:48
     */
    @Operation(summary = "导出商品分类关联")
    @SaCheckPermission("/biz/goodscategoryjoin/exportData")
    @PostMapping(value = "/biz/goodscategoryjoin/exportData", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportData(@RequestBody List<SxoGoodsCategoryJoinIdParam> sxoGoodsCategoryJoinIdParamList, HttpServletResponse response) throws IOException {
        sxoGoodsCategoryJoinService.exportData(sxoGoodsCategoryJoinIdParamList, response);
    }
}
